package com.difsonapps.contacttranslator.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.input.SAXBuilder;
import org.springframework.transaction.annotation.Transactional;


public class Generator {
    Namespace ns;
	File fXmlFile;
	Document doc;

	public Generator(File fXmlFile) {
		super();
		this.fXmlFile = fXmlFile;
		ns = Namespace.getNamespace("http://www.w3.org/2001/XMLSchema");
		try {
			SAXBuilder builder = new SAXBuilder();
			 doc = (Document) builder.build(fXmlFile);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	public List<DTOElement> getAttributs(Element complexTypeElement) {
		List<DTOElement> dTOElements = new ArrayList<DTOElement>();
		
		List<Element> listOfElement = complexTypeElement.getChildren("xs:element");
		for(Element element : listOfElement)
		{
			dTOElements.add(new DTOElement(element.getAttributeValue("name"),element.getAttributeValue("type")));
		}
		
		return dTOElements;
	}
	

	
	public static void main(String[] args)
	{
		File file = new File("NewXMLSchema1.xsd");
		Generator dg = new Generator(file);
		DAOGenerator daoG = new DAOGenerator(dg.doc, dg.ns);
		ServiceGenerator serviceG = new ServiceGenerator(dg.doc, dg.ns);
		ServiceImplGenerator serviceImpl = new ServiceImplGenerator(dg.doc, dg.ns);
		daoG.generate();
		serviceG.generate();
		serviceImpl.generate();
	}
	
	
}
